<?php
/**
 * @file features_report.database.inc
 *
 * Ce fichier rassemble tous les hooks virtuels permettant auc modules
 * de fournir un tableau des éléments dont ils disposent en base
 */
 
/**
 * Implements hook_in_database();
 * @see context.module
 */
function context_in_database() {   
  $contexts = context_contexts();
  $contexts_in_database = array();
  foreach ($contexts as $identifier => $context) {
    // we don't want default and overriden contexts
    if($context->type == CONTEXT_STORAGE_NORMAL) {
      $contexts_in_database[] = $identifier;
    }
  }
  return $contexts_in_database;
}
  
/**
 * Retourne cck fields. fields can only live in database anyway.
 * Implements hook_in_database();
 * @see content.module
 */
function content_in_database() {
  $elements_in_base = array();
  foreach(content_types() as $type_name => $datas) {
    foreach ($datas['fields'] as $field_name => $datas) {
      // dans les .infos des features, les champs cck contiennent à la fois le nom du champ et du type de contenu
      // on formate notre tableau de la même façon pour faire le diff facilement.
      $elements_in_base[] = $type_name. '-' . $field_name;
    }      
  }
  return $elements_in_base;
}
  
/**
 * implements hook_in_database()
 * @see imagecache.module
 */
function imagecache_in_database() {
  $imagecache = array();
  foreach (imagecache_presets() as $preset) {
    if($preset['storage'] == IMAGECACHE_STORAGE_NORMAL) {
      $imagecache[] = $preset['presetname'];
    }
  }
  return $imagecache;
}
  
/**
 * implements component_in_database()
 * @see fieldgroup.module
 */
function fieldgroup_in_database() {
  $fieldgroups = array();
  foreach(content_types() as $content_type => $datas) {
    foreach (fieldgroup_groups($content_type) as $fieldgroup_name => $datas) {
      $fieldgroups[] = $content_type . '-' . $fieldgroup_name;
    }
  }
  return $fieldgroups;
}
  
/**
 * implements hook_in_database()
 * @see views.module
 */
function views_in_database($reset = FALSE) {
  $views_names = array();
  if ($views = views_get_all_views()) {
    foreach ($views as $view)  {
      if ($view->type == 'Normal') {
        $views_names[] = $view->name;
      }
    }
  }
  return $views_names;
}